<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 
    setTimeout 会白一下, requestAnimationFrame 流畅
    requestAnimationFrame 的步伐跟着系统的刷新步伐走，
    它能保证回调函数在屏幕每一次的刷新间隔中被执行一次，不会丢帧了
    不在一个频道上
    -->
    <ul id="container"></ul>
    <script>
        let ul = document.getElementById('container');
        let total = 100000;
        let once = 20;
        let page = total/once;
        let index = 0;
        function loop(curTotal, curIndex) {
            if (curTotal <= 0) {
                return;
            }
            let pageCount = Math.min(curTotal, once);
            requestAnimationFrame(function() {
                let fragment = document.createDocumentFragment();
                for (let i = 0; i < pageCount; i++) {
                    let li = document.createElement('li');
                    li.innerText = curIndex + i + ':' + (Math.random() * total);
                    fragment.appendChild(li);
                }
                ul.appendChild(fragment);
                loop(curTotal - pageCount, curIndex + pageCount);
            })
        }
        loop(total, index);
    </script>
</body>
</html>